package com.dyc.WelcomeWidget;

import android.content.Intent;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import com.dyc.MainActivity;
import com.dyc.R;
import com.dyc.Adapter.ViewpagerAdapter;

import org.xutils.view.annotation.Event;
import org.xutils.view.annotation.ViewInject;
import org.xutils.x;

import java.util.ArrayList;
import java.util.List;

public class WelcomeGuideActivity extends AppCompatActivity {

    @ViewInject(R.id.welcome_viewpager_btn)
    private Button welcomeViewpagerBtn;

    @ViewInject(R.id.welcome_viewpager)
    private ViewPager welcomeViewpager;

    private List<View> pageList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_welcome_guide);
        x.view().inject(this);
        initViewPager();
    }

    @Event(value = {R.id.welcome_viewpager_btn})
    private void handleClick(View view) {
        startActivity(new Intent(WelcomeGuideActivity.this, MainActivity.class));
        finish();

    }

    // init viewpager
    private void initViewPager() {
        pageList = new ArrayList<>();
        ImageView iv = new ImageView(this);
        iv.setImageResource(R.drawable.guide_01);
        pageList.add(iv);
        ImageView iv1 = new ImageView(this);
        iv1.setImageResource(R.drawable.guide_02);
        pageList.add(iv1);
        ImageView iv2 = new ImageView(this);
        iv2.setImageResource(R.drawable.guide_03);
        pageList.add(iv2);
        welcomeViewpager.setAdapter(new ViewpagerAdapter(pageList));
        welcomeViewpager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int i, float v, int i1) {

            }

            @Override
            public void onPageSelected(int i) {
                if (i == pageList.size() - 1) {
                    welcomeViewpagerBtn.setVisibility(View.VISIBLE);
                } else {
                    welcomeViewpagerBtn.setVisibility(View.GONE);
                }
            }

            @Override
            public void onPageScrollStateChanged(int i) {

            }
        });
    }

}
